<template>
	<el-drawer style="padding: 0" v-model="visible" :show-close="false" :destroy-on-close="true" size="100%">
		<template #header="{ close, titleId, titleClass }">
			<span :id="titleId" :class="titleClass">
				{{ title }}
				&nbsp;
				<el-button type="primary" :loading="btnLoading" @click="saveFormBtn" v-if="controlType == 'edit'">保存</el-button>
			</span>
			<el-button class="btnReturn" @click="goback">返回</el-button>
		</template>
		<div style="display: flex; flex-direction: row; align-items: center; justify-content: space-between">
			<span>
				EMPI号：<span style="color: #5774f4">{{ dataForm.empi }}</span>
			</span>
			<span>
				<el-button type="primary" @click="getMergedInfo">合并信息</el-button>
			</span>
		</div>
		<!-- <el-scrollbar style="overflow: hidden auto; width: 100%; height: calc(100% - 50px)"> -->
		<div style="font-weight: 600; line-height: 30px; background: #f7f8fa; color: #1d2129; padding-left: 16px; margin: 10px 0">患者基本信息</div>

		<el-form :disabled="controlType != 'edit'" ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" class="patient-form">
			<el-row>
				<el-col :span="8">
					<el-form-item prop="pttNm" label="姓名">
						<el-input v-model="dataForm.pttNm" style="width: 100%" placeholder="请输入姓名"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="gdrCd" label="性别" style="width: 100%">
						<fast-select
							disabled
							v-model="dataForm.gdrCd"
							style="width: 100%"
							dict-type="mpi_gdr_cd"
							placeholder="请选择性别"
							clearable
							filterable
						></fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="age" label="年龄">
						<el-input style="width: 100%" v-model="dataForm.age" disabled placeholder="请输入年龄"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col :span="8">
					<el-form-item prop="idCard" label="证件类型" style="width: 100%" :rules="{ required: true }">
						<el-select disabled v-model="dataForm.idCard" style="width: 100%">
							<el-option label="身份证" value="01">身份证</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="idCrdNo" label="证件号" :rules="{ required: true }">
						<el-input disabled style="width: 100%" v-model="dataForm.idCrdNo" placeholder="请输入证件号"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="slfTelNo" label="联系电话">
						<el-input v-model="dataForm.slfTelNo" style="width: 100%" placeholder="请输入联系电话"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="aboCd" label="ABO血型">
						<fast-select
							v-model="dataForm.aboCd"
							style="width: 100%"
							dict-type="mpi_abo_cd"
							placeholder="请选择ABO血型"
							clearable
							filterable
						></fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="rhCd" label="Rh血型">
						<fast-select
							v-model="dataForm.rhCd"
							style="width: 100%"
							dict-type="mpi_rh_cd"
							placeholder="请选择Rh血型"
							clearable
							filterable
						></fast-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="ntnlyCd" label="国籍">
						<fast-select v-model="dataForm.ntnlyCd" style="width: 100%" dict-type="mpi_ntnly_cd" placeholder="请选择国籍" clearable filterable>
						</fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="ntnCd" label="民族">
						<fast-select
							v-model="dataForm.ntnCd"
							style="width: 100%"
							dict-type="mpi_ntn_cd"
							placeholder="请选择民族"
							clearable
							filterable
						></fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="bthDt" label="出生日期">
						<el-input disabled v-model="dataForm.bthDt" style="width: 100%" placeholder="请选择出生日期"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="mryCdtCd" label="婚姻状况">
						<fast-select v-model="dataForm.mryCdtCd" style="width: 100%" placeholder="请选择婚姻状况" dict-type="mpi_mry_cdt_cd" clearable filterable>
						</fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="eduCd" label="学历">
						<fast-select
							v-model="dataForm.eduCd"
							style="width: 100%"
							placeholder="请选择学历"
							dict-type="mpi_edu_cd"
							clearable
							filterable
						></fast-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="age" label="单位名称">
						<el-input v-model="dataForm.wrkUntNm" style="width: 100%" placeholder="请输入工作单位名称"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="age" label="单位电话">
						<el-input v-model="dataForm.wrkUntTelNo" style="width: 100%" placeholder="请输入工作单位电话"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="mdcrCgyCd" label="医疗支付方式">
						<fast-select
							v-model="dataForm.mdcrCgyCd"
							style="width: 100%"
							placeholder="请选择医疗支付方式"
							dict-type="mpi_mdcr_cgy_cd"
							clearable
							filterable
						>
						</fast-select>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item prop="pfsCgyCd" label="职业类别">
						<fast-select v-model="dataForm.pfsCgyCd" style="width: 100%" placeholder="请选择职业类别" dict-type="mpi_pfs_cgy_cd" clearable filterable>
						</fast-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item prop="dthFlg" label="本人死亡标识">
						<el-radio-group v-model="dataForm.dthFlg" style="width: 100%">
							<el-radio :label="0">未死亡</el-radio>
							<el-radio :label="1">已死亡</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="8"></el-col>
				<el-col :span="8"></el-col>
			</el-row>

			<!-- <el-form-item prop="joinWrkDt" label="参加工作日期">
				<el-date-picker v-model="dataForm.joinWrkDt" style="width: 100%" type="date" placeholder="请选择工作日期" />
			</el-form-item>
			<el-form-item prop="dthFlg" label="本人死亡标识">
				<el-select filterable v-model="dataForm.dthFlg" style="width: 100%">
					<el-option :label="'已死亡'" :value="'1'"></el-option>
					<el-option :label="'未死亡'" :value="'0'"></el-option>
				</el-select>
			</el-form-item> -->
		</el-form>
		<div style="font-weight: 600; line-height: 30px; background: #f7f8fa; color: #1d2129; padding-left: 16px; margin-bottom: 10px">其他信息</div>

		<el-tabs class="patient-info-tabs" v-model="activeName" @tab-change="tabsChange" type="border-card">
			<el-tab-pane label="地址信息" name="1">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit'" :icon="Plus" type="primary" @click="addUpdateAddressEvent('')">新增</el-button>
				</div>
				<el-table :data="addressTableData" style="width: 100%" max-height="250" size="small">
					<fast-table-column prop="addrTpCd" label="地址类型" dict-type="mpi_addr_tp_cd" headerAlign="left" align="left"></fast-table-column>
					<el-table-column prop="addrDscpt" label="地址信息" headerAlign="left" align="left" />
					<el-table-column prop="postCd" width="120" label="邮编" headerAlign="left" align="left" />
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" @click="addUpdateAddressEvent(scope.row)"> 修改 </el-button>
							<el-button link type="danger" size="small" @click="deleteAddress(scope.row.id)"> 删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-tab-pane>
			<el-tab-pane label="卡信息" name="2">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit'" :icon="Plus" type="primary" @click="addUpdateCardEvent('')">新增</el-button>
				</div>
				<el-table :data="cardTableData" style="width: 100%" max-height="250" size="small">
					<fast-table-column prop="crdTpCd" label="卡类型" dict-type="mpi_crd_tp_cd" headerAlign="left" align="left"></fast-table-column>
					<el-table-column prop="crdNo" label="卡号" headerAlign="left" align="left" />
					<el-table-column prop="crdStts" label="卡状态" headerAlign="left" align="left">
						<template #default="scope">
							{{ scope.row.crdStts ? '异常' : '正常' }}
						</template>
					</el-table-column>
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" @click="addUpdateCardEvent(scope.row)"> 修改 </el-button>
							<el-button link type="danger" size="small" @click="cardDelete(scope.row.id)"> 删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-tab-pane>
			<el-tab-pane label="证件信息" name="3">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit'" :icon="Plus" type="primary" @click="addUpdateCertificateEvent('')">新增</el-button>
				</div>
				<el-table :data="idCrdTableData" style="width: 100%" max-height="250" size="small">
					<fast-table-column prop="idCrdTpCd" label="证件类型" dict-type="mpi_id_crd_cgy_cd" headerAlign="left" align="left"></fast-table-column>
					<el-table-column prop="idCrdNo" label="证件号" headerAlign="left" align="left" />
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" v-if="scope.row.idCrdTpCd != '01'" @click="addUpdateCertificateEvent(scope.row)">
								修改
							</el-button>
							<el-button link type="danger" size="small" v-if="scope.row.idCrdTpCd != '01'" @click="deleteCerttificate(scope.row.id)">
								删除
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-tab-pane>
			<el-tab-pane label="联系人信息" name="4">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit'" :icon="Plus" type="primary" @click="addUpdatePersonEvent('')">新增</el-button>
				</div>
				<el-table :data="perTableData" style="width: 100%" max-height="250" size="small">
					<fast-table-column prop="ctctRltTpCd" label="与本人关系" dict-type="mpi_ctct_rlt_tp_cd" headerAlign="left" align="left"></fast-table-column>
					<el-table-column prop="ctctRltNm" label="联系人" headerAlign="left" align="left" />
					<el-table-column prop="ctctTelNo" label="联系方式" headerAlign="left" align="left" />
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" @click="addUpdatePersonEvent(scope.row)"> 修改 </el-button>
							<el-button link type="danger" size="small" @click="deletePerson(scope.row.id)"> 删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-tab-pane>
			<el-tab-pane label="建档信息" name="5">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit' && recTableData.length < 1" :icon="Plus" type="primary" @click="addUpdateCrtRcdEvent('')"
						>新增</el-button
					>
				</div>
				<el-table :data="recTableData" style="width: 100%" max-height="250" size="small">
					<el-table-column prop="crtRcdOrgNm" label="建档医疗机构" headerAlign="left" align="left" />
					<el-table-column prop="crtRcdDctNm" label="建档医生" headerAlign="left" align="left" />
					<el-table-column prop="crtRcdDt" label="建档日期" headerAlign="left" align="left" />
					<el-table-column prop="crtRcdStrtDt" label="建档生效日期" headerAlign="left" align="left" />
					<el-table-column prop="rcdSttsCd" label="建档状态" headerAlign="left" align="left">
						<template #default="scope">
							{{ scope.row.rcdSttsCd == '0' ? '正常' : '异常' }}
						</template>
					</el-table-column>
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" @click="addUpdateCrtRcdEvent(scope.row)"> 修改 </el-button>
							<el-button link type="danger" size="small" @click="deleteCrtRcd(scope.row.id)"> 删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- <el-button v-if="controlType == 'edit'" :icon="Plus" type="primary">新增</el-button> -->
			</el-tab-pane>
			<el-tab-pane label="签约信息" name="6">
				<div style="text-align: right; margin-bottom: 5px">
					<el-button v-if="controlType == 'edit' && qyTableData.length < 1" :icon="Plus" type="primary" @click="addUpdateSgnCtrctEvent('')"
						>新增</el-button
					>
				</div>
				<el-table :data="qyTableData" style="width: 100%" max-height="250" size="small">
					<el-table-column prop="sgnCtrctOrgNm" label="签约医疗机构" headerAlign="left" align="left" />
					<el-table-column prop="sgnCtrctDctNm" label="签约医生" headerAlign="left" align="left" />
					<el-table-column prop="sgnCtrctDt" label="签约日期" headerAlign="left" align="left" />
					<el-table-column prop="sgnCtrctStrtDt" label="签约生效日期" headerAlign="left" align="left" />
					<el-table-column prop="sgnCtrctExprDt" label="签约到期日期" headerAlign="left" align="left" />
					<el-table-column prop="sgnCtrctSttsCd" label="签约状态" headerAlign="left" align="left">
						<template #default="scope">
							{{ scope.row.sgnCtrctSttsCd == '0' ? '正常' : '异常' }}
						</template>
					</el-table-column>
					<el-table-column label="操作" v-if="controlType == 'edit'" headerAlign="left" align="left">
						<template #default="scope">
							<el-button link type="primary" size="small" @click="addUpdateSgnCtrctEvent(scope.row)"> 修改 </el-button>
							<el-button link type="danger" size="small" @click="deleteSgnCtrct(scope.row.id)"> 删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- <el-button v-if="controlType == 'edit'" :icon="Plus" type="primary">新增</el-button> -->
			</el-tab-pane>
		</el-tabs>
		<!-- </el-scrollbar> -->

		<!-- 地址信息新增编辑 -->
		<AddUpdateAddress ref="addUpdateAddressRef" @close="getAddressData" />
		<!-- 卡信息 -->
		<AddUpdateCard ref="addUpdateCardRef" @close="getCrdData"></AddUpdateCard>
		<!-- 证件信息 -->
		<AddUpdateCertificate ref="addUpdateCertificateRef" @close="getCertData"></AddUpdateCertificate>
		<!-- 联系人信息 -->
		<AddUpdatePerson ref="addUpdatePersonRef" @close="getPersonData"></AddUpdatePerson>
		<!-- 建档信息 -->
		<AddUpdateCrtRcd ref="addUpdateCrtRcdRef" @close="getFileData"></AddUpdateCrtRcd>
		<!-- 签约信息 -->
		<AddUpdateSgnCtrct ref="addUpdateSgnCtrctRef" @close="getSignData"></AddUpdateSgnCtrct>

		<el-drawer style="padding: 0" v-model="mergedVisible" :show-close="false" :destroy-on-close="true" size="40%">
			<template #header="{ titleId, titleClass }">
				<span :id="titleId" :class="titleClass">
					EMPI号：<span style="color: #5774f4">{{ dataForm.empi }}</span>
				</span>
			</template>
			<el-table :data="mergedTable" border max-height="calc(100vh - 280px )" style="width: 100%">
				<el-table-column prop="prmKey" label="主键" width="100" align="center"> </el-table-column>
				<el-table-column prop="margeTime" label="合并时间" header-align="center" align="center"></el-table-column>
				<el-table-column prop="margeStatus" label="合并方式" header-align="center" align="center">
					<template #default="scope">
						{{ scope.row.margeStatus == 1 ? '自动合并' : '手动合并' }}
					</template>
				</el-table-column>

				<el-table-column prop="isValid" label="是否有效" header-align="center" align="center"></el-table-column>
			</el-table>
		</el-drawer>
	</el-drawer>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'

import AddUpdateAddress from './addUpdateAddress.vue'
import AddUpdateCard from './addUpdateCard.vue'
import AddUpdateCertificate from './addUpdateCertificate.vue'
import AddUpdatePerson from './addUpdatePerson.vue'
import AddUpdateCrtRcd from './addUpdateCrtRcd.vue'
import AddUpdateSgnCtrct from './addUpdateSgnCtrct.vue'

import {
	getPatientDetail,
	getPatientAddress,
	getCardList,
	getCertList,
	getFileList,
	getPatientPerson,
	getSignList,
	updatePatient,
	deletePatientAddress,
	deleteCard,
	deleteCert,
	deletePatientPerson,
	getMergeList,
	deleteFile,
	deleteSign
} from '@/api/patient-primary/patient-mana'
import { ElMessage } from 'element-plus'

const props = defineProps({
	adcd: {
		type: Array,
		default: []
	}
})

const emit = defineEmits(['close', 'back'])
const btnLoading = ref(false)

const visible = ref(false)
const mergedVisible = ref(false)
const title = ref('')
const idCard = ref('01')
const dataFormRef = ref()
const dataForm = reactive({
	idCard: '01',
	currAddrDscpt: '',
	pttNm: '',
	gdrCd: '',
	idCrdNo: '',
	slfTelNo: '',
	aboCd: '',
	rhCd: '',
	ntnlyCd: '',
	ntnCd: '',
	bthDt: '',
	mryCdtCd: '',
	eduCd: '',
	wrkUntNm: '',
	wrkUntTelNo: '',
	mdcrCgyCd: '',
	pfsCgyCd: '',
	joinWrkDt: '',
	age: ''
})

const controlType = ref('')

const addressTableData = ref([])
const cardTableData = ref([])
const idCrdTableData = ref([])
const perTableData = ref([])
const recTableData = ref([])
const qyTableData = ref([])

const dataRules = ref({
	pttNm: [
		{
			required: true,
			message: '姓名为必填项',
			trigger: 'blur'
		}
	],
	slfTelNo: [
		{
			required: true,
			trigger: 'blur',
			validator: (rule, value, callback) => {
				if (value == '') {
					return callback(new Error('联系电话为必填项'))
				}
				let _tel = /^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/
				if (_tel.test(value)) {
					callback()
				}
				return callback(new Error('请输入正确的联系电话'))
			}
		}
	]
})
const activeName = ref('1')

const mergedTable = ref([])

const init = (id, type) => {
	mergedVisible.value = false
	btnLoading.value = false
	controlType.value = type
	dataForm.empi = id
	activeName.value = '1'
	visible.value = true
	if (type == 'edit') {
		title.value = '编辑患者主索引'
	} else {
		title.value = '查看患者主索引'
	}

	// 详情
	if (id) {
		getDetail(id)

		getAddressData(id)
	}
}

const getDetail = id => {
	getPatientDetail(id).then(res => {
		if (res.data) {
			Object.assign(dataForm, res.data)

			if (dataForm.idCrdNo) {
				dataForm.age = idCardToAge(dataForm.idCrdNo).age
				// dataForm.gdrCd = idCardToAge(dataForm.idCrdNo).sex
			}
		}
	})
}

const saveFormBtn = () => {
	dataFormRef.value.validate(valid => {
		if (!valid) return
		// 表单验证通过，进行表单提交

		if (dataForm.joinWrkDt) {
			dataForm.joinWrkDt = timeFormater(dataForm.joinWrkDt).format('YYYY-MM-DD')
		}

		console.log(dataForm)

		btnLoading.value = true
		updatePatient(dataForm)
			.then(res => {
				ElMessage.success({
					message: '保存成功',
					duration: 500,
					onClose: () => {
						btnLoading.value = false
						visible.value = false
						emit('close')
					}
				})
			})
			.catch(() => {
				btnLoading.value = false
			})
	})
}

const goback = () => {
	visible.value = false
	emit('back')
}

// 合并信息
const getMergedInfo = () => {
	mergedVisible.value = true
	mergedTable.value = []
	getMergeList({ empi: dataForm.empi }).then(res => {
		if (res.data) {
			mergedTable.value = res.data
		}
	})
}

// 地址信息  新增编辑
const addUpdateAddressRef = ref()
const addUpdateAddressEvent = data => {
	addUpdateAddressRef.value.init(data, dataForm.empi, props.adcd)
}

// 地址信息 删除
const deleteAddress = id => {
	deletePatientAddress({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getAddressData()
			}
		})
	})
}

// 卡信息
const addUpdateCardRef = ref()
const addUpdateCardEvent = data => {
	addUpdateCardRef.value.init(data, dataForm.empi)
}

// 卡信息 删除
const cardDelete = id => {
	deleteCard({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getCrdData()
			}
		})
	})
}

// 证件信息
const addUpdateCertificateRef = ref()
const addUpdateCertificateEvent = data => {
	addUpdateCertificateRef.value.init(data, dataForm.empi)
}

// 证件信息 删除
const deleteCerttificate = id => {
	deleteCert({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getCertData()
			}
		})
	})
}

// 联系人
const addUpdatePersonRef = ref()
const addUpdatePersonEvent = data => {
	addUpdatePersonRef.value.init(data, dataForm.empi)
}

// 联系人 删除
const deletePerson = id => {
	deletePatientPerson({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getPersonData()
			}
		})
	})
}

// 建档信息
const addUpdateCrtRcdRef = ref()
const addUpdateCrtRcdEvent = data => {
	addUpdateCrtRcdRef.value.init(data, dataForm.empi)
}
const deleteCrtRcd = id => {
	deleteFile({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getFileData()
			}
		})
	})
}

// 签约信息
const addUpdateSgnCtrctRef = ref()
const addUpdateSgnCtrctEvent = data => {
	addUpdateSgnCtrctRef.value.init(data, dataForm.empi)
}

const deleteSgnCtrct = id => {
	deleteSign({ id: id }).then(res => {
		ElMessage.success({
			message: '删除成功',
			duration: 500,
			onClose: () => {
				getSignData()
			}
		})
	})
}

const tabsChange = e => {
	activeName.value = e
	switch (Number(e)) {
		case 1:
			getAddressData()
			break
		case 2:
			getCrdData()
			break
		case 3:
			getCertData()
			break
		case 4:
			getPersonData()
			break
		case 5:
			getFileData()
			break
		case 6:
			getSignData()
			break
	}
}

const getAddressData = () => {
	addressTableData.value = []
	getPatientAddress({ empi: dataForm.empi }).then(res => {
		addressTableData.value = res.data
	})
}

const getCrdData = () => {
	cardTableData.value = []
	getCardList({ empi: dataForm.empi }).then(res => {
		cardTableData.value = res.data
	})
}

const getCertData = () => {
	idCrdTableData.value = []
	getCertList({ empi: dataForm.empi }).then(res => {
		idCrdTableData.value = res.data
	})
}

const getPersonData = () => {
	perTableData.value = []
	getPatientPerson({ empi: dataForm.empi }).then(res => {
		perTableData.value = res.data
	})
}

const getFileData = () => {
	recTableData.value = []
	getFileList({ empi: dataForm.empi }).then(res => {
		recTableData.value = res.data
	})
}

const getSignData = () => {
	qyTableData.value = []
	getSignList({ empi: dataForm.empi }).then(res => {
		qyTableData.value = res.data
	})
}

const idCardToAge = userCard => {
	let yearBirth: any = ''
	let monthBirth: any = ''
	let dayBirth: any = ''
	let sex: any = ''
	let age: any = ''
	if (userCard) {
		if (userCard.length == 15) {
			var org_birthday = userCard.substring(6, 12)
			//获取出生年月日
			yearBirth = '19' + org_birthday.substring(0, 2)
			monthBirth = org_birthday.substring(2, 4)
			dayBirth = org_birthday.substring(4, 6)
			sex = userCard.substring(14, 15) % 2 == 0 ? '2' : '1'
		} else if (userCard.length == 18) {
			//获取出生年月日 性别
			yearBirth = userCard.substring(6, 10)
			monthBirth = userCard.substring(10, 12)
			dayBirth = userCard.substring(12, 14)
			sex = userCard.substring(16, 17) % 2 == 0 ? '2' : '1'
		}
		//获取当前年月日并计算年龄
		var myDate = new Date()
		var monthNow = myDate.getMonth() + 1
		var dayNow = myDate.getDate()
		age = myDate.getFullYear() - yearBirth
		if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
			age--
		}
		//返回年龄、出生年月
		return { age: age, birthday: yearBirth + '-' + monthBirth + '-' + dayBirth, sex: sex }
	} else {
		return { age: '', birthday: '', sex: '' }
	}
}

defineExpose({
	init
})
</script>
<style lang="scss" scoped>
// .demo-tabs > .el-tabs__content {
// 	min-height: 600px;
// }

.patient-form .el-form--inline .el-form-item {
	width: 100%;
}
</style>
